﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web;
using Dinner.Models.Validation;

namespace Dinner.Models
{
	public partial class Menu
	{
		public bool IsValid
		{
			get { return (GetRuleViolations().Count() == 0); }
		}

		partial void OnValidate(ChangeAction action)
		{
			if (!IsValid)
				throw new ApplicationException("Rule violations prevent saving");
		}

		public IEnumerable<RuleViolation> GetRuleViolations()
		{
			if (date == DateTime.MinValue)
				yield return new RuleViolation("Date is required", "Date");
			yield break;
		}
	}
}
